package com.guigu.serviceorder.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.guigu.common_util.pojo.utils.Result;
import com.guigu.serviceorder.entity.TbStatistical;
import com.guigu.serviceorder.service.ITbStatisticalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jobob
 * @since 2020-07-17
 */
@RestController
@RequestMapping("/serviceorder/tb-statistical")
public class TbStatisticalController {

    @Autowired
    private ITbStatisticalService iTbStatisticalService;


    /**
     * 交易数据
     * @param date1
     * @param date2
     * @return
     */
    @GetMapping("/list")
    public Result list(String date1,String date2){
        QueryWrapper<TbStatistical> wrapper=new QueryWrapper();
        if (date1!= null && !"".equals(date1)){
            wrapper.ge("creattime",date1);
        }
        if (date2!= null && !"".equals(date2)){
            wrapper.le("creattime",date2);
        }
        List<TbStatistical> list = iTbStatisticalService.list(wrapper);

        return Result.ok().data("list",list);
    }

    @GetMapping("/select")
    public Result select(){
        TbStatistical tbStatistical=new TbStatistical();
        TbStatistical selectnumber = iTbStatisticalService.selectnumber();
        TbStatistical selectamount = iTbStatisticalService.selectamount();
        TbStatistical selectonum = iTbStatisticalService.selectonum();
        TbStatistical selectorders = iTbStatisticalService.selectorders();
        TbStatistical selectovalid = iTbStatisticalService.selectovalid();
        TbStatistical selectpayment = iTbStatisticalService.selectpayment();
        TbStatistical selectquantity = iTbStatisticalService.selectquantity();

        if (selectnumber!=null){
            tbStatistical.setNumber(selectnumber.getNumber());
        }
        if (selectorders!=null){
            tbStatistical.setOrders(selectorders.getOrders());
            tbStatistical.setOmoney(selectorders.getOmoney());
        }
        if (selectonum!=null){
            tbStatistical.setOnum(selectonum.getOnum());
        }
        if (selectovalid!=null){
            tbStatistical.setOvalid(selectovalid.getOvalid());
        }
        if (selectamount!=null){
            tbStatistical.setAmount(selectamount.getAmount());
        }
        if (selectpayment!=null){
            tbStatistical.setPayment(selectpayment.getPayment());
        }
        if (selectquantity!=null){
            tbStatistical.setQuantity(selectquantity.getQuantity());
            tbStatistical.setPamount(selectquantity.getPamount());
            tbStatistical.setPrice(selectquantity.getPrice());
        }
        boolean save = iTbStatisticalService.save(tbStatistical);
        if (save==true)
            return Result.ok();
        return Result.error();
    }

}

